<?php

class Seniorstaff_Model
{
	/**
	 * Holds instance of database connection
	 */
	private $db;
	private $page_data = array();
	private $senior_staff_content;
	
	public function __construct()
	{
		$this->db = new MysqlImproved_Driver;
	}
	
	public function get_senior_staff($people){
		
		$this->db->connect();
		$this->get_page_data();
		$article['page_title'] = $this->page_data['title'];
		$article['page_description'] = $this->page_data['description'];
		$article['senior_staff_content'] = $this->get_the_data_of_senior($people);
		$article['description'] = $this->get_seniorstaff_description($people);
		$article['keywords'] = $this->get_seniorstaff_keywords($people);
		return $article;
		
	}
	
	
	
	public function get_the_data_of_senior($people){
		// prepare query
		$people = $this->db->escape($people);
		$this->db->prepare(
				"
				SELECT
				`staff_link`,
				`staff_image`,
				`staff_name`,
				`staff_email`,
				`staff_position`,
				`staff_description`,
				`staff_content`
				FROM
				`senior_staff`
				WHERE
				`staff_link` = '$people'
				LIMIT 
				1
				;
				"
		);
		$this->db->query();
		$this->senior_staff_content = "";
		while($staff_data = $this->db->fetch('array')){
			$this->senior_staff_content .= "
				<a class=\"lightbox\" href=\"../images/staff/".$staff_data['staff_image']."\" title=\"".$staff_data['staff_name']."\"><img class=\"left\" src=\"/views/images/".$staff_data['staff_image']."\" alt=\"".$staff_data['staff_description']."\" /></a>
					<div id=\"item-info\" class=\"item-info\">
						<h4 class=\"item-h left\">".$staff_data['staff_name']."</h4>
						<a href=\"mailto:".$staff_data['staff_email']."\"><img class=\"left mail\" src=\"../images/ico-mail.png\" alt=\"send e-mail\" /></a>
						<span class=\"right\">".$staff_data['staff_position']."</span>
						<div id=\"item-parag\" class=\"clear\">
							".$staff_data['staff_content']."
						</div>
					</div><!-- End Staff Item -->
			";
		}
		return $this->senior_staff_content;
	}
	
	public function get_seniorstaff_description($people){
	
		$this->db->prepare(
				"
				SELECT
				`staff_meta_description`
				FROM
				`senior_staff`
				WHERE
				`staff_link` = '$people'
				LIMIT
				1
				;
				"
		);
		$this->db->query();
		while($staff_data = $this->db->fetch('array')){
			$staff_description = $staff_data['staff_meta_description'];
		}
		return $staff_description;
	}
	
	public function get_seniorstaff_keywords($people){
		$this->db->prepare(
				"
				SELECT
				`staff_keywords`
				FROM
				`senior_staff`
				WHERE
				`staff_link` = '$people'
				LIMIT
				1
				;
				"
		);
		$this->db->query();
		while($staff_datas = $this->db->fetch('array')){
			$staff_keywords = $staff_datas['staff_keywords'];
		}
		return $staff_keywords;
	}
	
	public function get_page_data(){
		//prepare query
		$this->db->prepare
		(
				"
				SELECT
				`page`,
				`title`,
				`description`,
				`keywords`
				FROM
				`page_description`
				WHERE
				`page` = 'staff'
				LIMIT
				1
				;
				"
		);
	
		//execute query
		$this->db->query();
	
		$this->page_data = $this->db->fetch('array');
		return $this->page_data;
	}
}